我正在尝试在我的项目中的 3 个模块之间建立连接。当我尝试使用 @Autowired 到达我的对象时出现错误。我会稍微解释一下我的场景。
所有这些模块都在 pom.xml 内部连接。说说我的问题吧。
.
.
.
@Autowired
public CommuniticationRepository;
@Autowired
public Core core;
.
.
.
Run Code Online (Sandbox Code Playgroud)
public class Core {
private int id;
private String name;
private Date date;
public Core(int id, String name, Date date) {
this.id = id;
this.name = name;
this.date = date;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return …Run Code Online (Sandbox Code Playgroud) 我们正在ASP.NET MVC项目中尝试一些登录操作.我们的目标是:" 如果用户的IP不是来自我们的内部网,则将他/她重定向到登录页面.否则,只需转到我们的索引页面.我们编写了一些代码,但我们在一个循环中.
protected void Application_BeginRequest(object sender, EventArgs e)
{
var request = ((System.Web.HttpApplication) sender).Request;
string ip1 = request.UserHostAddress;
string shortLocalIP;
if (ip1 != null && ip1.Contains("."))
{
string[] ipValues = ip1.Split('.');
shortLocalIP = ipValues[0] +"."+ipValues[1];
}
else
{
shortLocalIP = "192.168";
}
//var ip2 = request.ServerVariables["LOCAL_ADDR"];
//var ip3 = request.ServerVariables["SERVER_ADDR"];
if (shortLocalIP != LOCALIP)
{
if ("/Login/User".Equals(request.RawUrl, StringComparison.InvariantCultureIgnoreCase))
{
return;
}
Response.Clear();
Response.Redirect("/Login/User");
Response.End();
}
}
Run Code Online (Sandbox Code Playgroud)
public class LoginController : Controller
{
// GET: Login
public …Run Code Online (Sandbox Code Playgroud) 当我想在c#中做一些操作时,我有一点问题.我会举一个小例子.
Stack<List<HufmannLetter>> steps = new Stack<List<HufmannLetter>>();
List<HufmannLetter> letterList = new List<HufmannLetter>();
while(true){
letterList.Add("asd");
letterList.Add("sad");
steps.Push(letterList);
letterlist.Clear();
}
Run Code Online (Sandbox Code Playgroud)
在此代码中,我想将我的链表推送到堆栈而不是删除列表中的所有项目.当我清除列表时,我的堆栈的第一个索引消失,因为它通过引用传递.我错了吗?因为我不知道为什么会这样.
所以我使用pass by value方法.
Stack<List<HufmannLetter>> steps = new Stack<List<HufmannLetter>>();
List<HufmannLetter> letterList = new List<HufmannLetter>();
while(true) {
letterList.Add("asd");
letterList.Add("sad");
List<HufmannLetter> tempLetterList = new List<HufmannLetter>(letterList);
steps.Push(tempLetterList);
letterlist.Clear();
}
Run Code Online (Sandbox Code Playgroud)
这是解决问题的好方法吗?这样它工作,但可读性降低.你有什么建议我的?
谢谢...
我试图通过在Java中使用executor来识别主机是活着还是死了.在我的情况下,我有严格的主机保留在列表中.
我的目标是创建具有多个主机并检查它们的线程.当线程与主机连接时,主机不会关闭连接,并且连续发送诸如50(死)或51(活动)的情况代码.
我的问题是线程只能在主机上连接.例如;
我有两个主机192.168.1.1和192.168.1.2.线程应该在后台检查它们,但我只能在1.1中连接
List <Host> hosts = LoadBalancer.getHostList();
ExecutorService executor = Executors.newFixedThreadPool(hosts.size());
executor.submit(()->{
for (Host host:hosts) {
try {
connect(host,"message",1);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Run Code Online (Sandbox Code Playgroud)
我还在HOST.java中同步了setActive函数
public class Host {
private String ip;
private int port;
private boolean isActive;
public Host(String ip, int port) {
this.ip = ip;
this.port = port;
this.isActive = true;
}
public synchronized boolean isActive() {
return isActive;
}
public synchronized void setActive(boolean active) {
isActive = active;
} …Run Code Online (Sandbox Code Playgroud) 我试图在 C 中将字符串转换为二进制。此函数必须返回一个字符串(char *),如“010010101”等。此外,我想打印返回的内容。我不能确定这个代码
char* stringToBinary(char* s)
{
if(s == NULL) return 0; /* no input string */
char *binary = malloc(sizeof(s)*8);
strcpy(binary,"");
char *ptr = s;
int i;
for(; *ptr != 0; ++ptr)
{
/* perform bitwise AND for every bit of the character */
for(i = 7; i >= 0; --i){
(*ptr & 1 << i) ? strcat(binary,"1") : strcat(binary,"0");
}
}
return binary;
}
Run Code Online (Sandbox Code Playgroud) 我在使用 JDBCTemplate 从我的数据库中获取一行时遇到了性能问题。当我在 plsql 中运行 sql 时,我可以在 3 毫秒内获得结果,但代码中的相同查询大约需要 200 毫秒。我认为它运行缓慢,因为在运行查询之前,创建了一个连接并且我在其中浪费了太多时间。我想我需要一个连接池或 smt。别的
在这里写代码之前,想先说一下我的spring boot项目的流程。客户端调用我的端点,在这个调用中,我使用了来自多个表的多个查询。所有查询都运行缓慢,因为对于每个查询,都会创建另一个连接。
@Configuration
public class DatabaseConfig {
@Autowired
private Environment env;
@Bean(name = "fraudDb")
public DataSource masterDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("driver-class-name"));
dataSource.setUrl(env.getProperty("fraud.url"));
dataSource.setUsername(env.getProperty("fraud.username"));
dataSource.setPassword(env.getProperty("fraud.password"));
return dataSource;
}
@Bean(name = "ndvliveDb")
public DataSource secondDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("driver-class-name"));
dataSource.setUrl(env.getProperty("ndvlive.url"));
dataSource.setUsername(env.getProperty("ndvlive.username"));
dataSource.setPassword(env.getProperty("ndvlive.password"));
return dataSource;
}
@Bean(name = "fraudJdbcTemplate")
@Autowired
public JdbcTemplate masterJdbcTemplate(@Qualifier("fraudDb") DataSource fraudDb) {
return new JdbcTemplate(fraudDb);
}
@Bean(name = "ndvliveJdbcTemplate")
@Autowired …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建并运行我的 Spring Boot 项目,该项目在页面上返回“我还活着”。我有基本的主类和一个休息控制器类。我想解决方案很简单,但我找不到任何与我相似的问题。
这是事情。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HealthCheck {
@GetMapping("/up")
public String checkHealth(){
return "I am alive";
}
}
Run Code Online (Sandbox Code Playgroud)
当我转到 localhost:8080/up 时,它返回为
白标错误页面 此应用程序没有明确的 /error 映射,因此您将其视为后备。
2018 年 9 月 25 日星期二 17:47:53 EEST 出现意外错误(类型 = 未找到,状态 = 404)。没有可用的消息
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo …Run Code Online (Sandbox Code Playgroud) 我正在尝试在名为CacheManager的类中使用存储库。这个存储库应该从表中获取所有行。尽管使用了@Autowired 注释,它还是为空。我在哪里失踪?谢谢。
@Repository
public interface FraudCacheListRepository extends CrudRepository<FraudCacheListEntity,Integer> {
List<FraudCacheListEntity> findAll();
}
Run Code Online (Sandbox Code Playgroud)
@Component
public class CacheManager {
private long second = 1000L;
private long minute = second * 60;
private long hour = minute * 60;
private long TTL = hour;
@Autowired
private FraudCacheListRepository fraudCacheListRepository;
public CacheManager() {
getAllTables();
}
private void getAllTables(){
List<FraudCacheListEntity> fraudCacheListEntities = fraudCacheListRepository.findAll();
for (FraudCacheListEntity entity:fraudCacheListEntities) {
System.out.println(entity.toString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
@Component
@Configurable
public class CoreController {
public ComController com;
@Autowired …Run Code Online (Sandbox Code Playgroud) 我试图只使用浮点数后的 8 位数字,并将其余数字四舍五入到上限。当输入为 0.0 时,在舍入操作之后,我0E-8改为0.00000000
val test = BigDecimal.valueOf(0.0)
println(test.setScale(8, RoundingMode.CEILING))
Run Code Online (Sandbox Code Playgroud)
当我将值更改为 2.0 时,结果正如我预期的那样2.00000000
我是 Kotlin 的新手。我不明白原因。
我有这个功能,它自己添加一个数字.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define ADD(x) (x)+(x)
int main()
{
int x = 2;
int y = ADD(++x);
cout << y << endl;
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个程序时,它返回8但我期待6.
我认为x = 3并且它正在向ADD函数发送3,但它似乎没有.有人可以向我解释一下吗?
java ×6
spring-boot ×3
c# ×2
spring ×2
asp.net ×1
asp.net-mvc ×1
autowired ×1
c ×1
c++ ×1
jdbctemplate ×1
kotlin ×1
repository ×1